var gerenszIndex = {
    init: function () {
        var json = [{
            "id": "gerenszIndexDiv",
            "title": "用户信息",
            "number": 3,
            "type": 12,
            "body": {
                "type": "1"
            },
            "clsTop": "5px"
        }, {
            "id": "gerenszIndexDiv2",
            "number": 9,
            "type": 10,
            "body": [
                { id: "gerenszIndexDiv21", title: "个人信息" },
                { id: "gerenszIndexDiv22", title: "修改密码" },
                // { id: "gerenszIndexDiv23", title: "APP应用" },
                // { id: "gerenszIndexDiv24", title: "小工具" },
                { id: "gerenszIndexDiv25", title: "公示栏" }
            ],
            "minHeight": "720px",
            "clsLeft": "5px",
            "clsTop": "5px"
        }]
        kaHtml.init("gerenszIndexDivHtml", json, 0, function () {
            var userInfor = gerenszIndex.getUserInfor();
            var roles = userInfor.roles;
            var tenant = userInfor.tenant;
            var gerenszIndexDiv21Html = `
            <blockquote class="layui-elem-quote">
                <div style="float: left;margin-right: 20px;">
                    账号：<span style="font-weight: bold;color: #0066ff;border: 1px dashed;padding: 2px;padding-left: 10px;padding-right: 10px;">` +
                (userInfor.user.status == 0 ? "正常" : userInfor.user.status == 1 ? "停用" : "") +
                `</span><br/>
                </div>
                <div>
                    工作：<span style="color: red;font-weight: bold;border: 1px dashed;padding: 2px;padding-left: 10px;padding-right: 10px;">正常上班</span>
                </div>
            </blockquote>
            <div id="gerenszIndexDiv21_content_wwww" class="layui-row">
                <div class="layui-col-xs1 ka-table-title">用户编码：</div>
                <div formid="userId" class="layui-col-xs11 ka-table-value1">` + userInfor.user.userId + `</div>
                <div class="layui-col-xs1 ka-table-title">最后登录IP：</div>
                <div formid="loginIp" class="layui-col-xs5 ka-table-value2">` + userInfor.user.loginIp + `</div>
                <div class="layui-col-xs1 ka-table-title">最后登录时间：</div>
                <div formid="loginDate" class="layui-col-xs5 ka-table-value2">` + userInfor.user.loginDate + `</div>
                <div class="layui-col-xs1 ka-table-title">昵称：</div>
                <div formid="nickName" class="layui-col-xs11 ka-table-value1" style="border: 0px solid #f0f0f0;background: #ffffff;">
                    <input id="nickNameId" type="text" placeholder="请填写昵称" value="` + userInfor.user.nickName + `" class="layui-input">
                </div>
            </div>
            <div style="width: 100%;margin-top: 20px;text-align: center;">
                <button type="button" onclick="gerenszIndex.updateNickName('` + userInfor.user.nickName + `','` + userInfor.user.userId + `')" class="layui-btn layui-btn-sm">
                    <i class="icon iconfont icon-duigou" style="font-size: 12px;margin-right: 5px;"></i> 确认修改
                </button>
            </div>
            `;
            $("#gerenszIndexDiv21_content").html(gerenszIndexDiv21Html);
            var gerenszIndexDiv22Html = `
            <div id="gerenszIndexDiv22_content_wwww" class="layui-row">
                <div class="layui-col-xs1 ka-table-title">原密码：</div>
                <div formid="oldPassword" class="layui-col-xs11 ka-table-value1" style="border: 0px solid #f0f0f0;background: #ffffff;">
                    <input type="password" autocomplete="off" lay-affix="eye" id="oldPasswordId" placeholder="请填写原密码" value="" class="layui-input">
                </div>
                <div class="layui-col-xs1 ka-table-title">新密码：</div>
                <div formid="newPassword" class="layui-col-xs11 ka-table-value1" style="border: 0px solid #f0f0f0;background: #ffffff;">
                    <input type="password" autocomplete="off" lay-affix="eye" id="newPasswordId" placeholder="请填写新密码" value="" class="layui-input">
                </div>
                <div class="layui-col-xs1 ka-table-title">重复新密码：</div>
                <div formid="newPasswordCF" class="layui-col-xs11 ka-table-value1" style="border: 0px solid #f0f0f0;background: #ffffff;">
                    <input type="password" autocomplete="off" lay-affix="eye" id="newPasswordCFId" placeholder="请填写重复新密码" value="" class="layui-input">
                </div>
            </div>
            <div style="width: 100%;margin-top: 20px;text-align: center;">
                <button type="button" onclick="gerenszIndex.updatePwd('` + userInfor.user.nickName + `','` + userInfor.user.userId + `')" class="layui-btn layui-bg-blue layui-btn-sm">
                    <i class="icon iconfont icon-duigou" style="font-size: 12px;margin-right: 5px;"></i> 确认修改
                </button>
            </div>
            `;
            $("#gerenszIndexDiv22_content").html(gerenszIndexDiv22Html);
            var giBody = {
                id: "grszGSLGrid",
                kaposition: "1003",
                fbAnd: true,
                fb: true,
                fsv: {},
                fv: [{
                    field: "newtype",
                    value: "1"
                }],//查询条件
                topbutton: {
                    type: 4, //【1:URL,2:本地JSON,3:外站URL,4:自定义JSON】
                    datajson: [
                        {
                            id: "grszGSLGridAddIdS",
                            title: "新增",
                            ico: `icon-plus-circle`,
                            cb: function (config) {
                                var uuid = ka.uuidStr();
                                var index = layui.layer.open({
                                    type: 1, // page 层类型
                                    area: ['537px', '360px'],
                                    title: `
                                    <i class="icon iconfont icon-mail" style="margin-top: 10px;text-align: center;width: 50px;height: 50px;line-height: 50px;font-size: 30px;float: left;position: absolute;background-color: #f3f1ff;border-radius: 50%;"></i>
                                    <div style="font-size: 18px;font-weight: bold;margin-left: 70px;margin-top: 5px;position: absolute;">新增公示栏</div>
                                    <div style="color: #989898;margin-top: 35px;margin-left: 70px;font-size: 12px;position: absolute;">用于自己推广</div>
                                    `,
                                    offset: ['20%', '30%'],
                                    shade: [0.6, '#FFF'], // 点击遮罩区域，关闭弹层
                                    maxmin: false, // 允许全屏最小化
                                    anim: 0, // 0-6 的动画形式，-1 不开启
                                    content: `
                                    <input type="hidden" id="newtype` + uuid + `" name="newtype" value="1" placeholder="类型" autocomplete="off" class="layui-input">
                                    <div style="padding-left: 15px;padding-right: 15px;padding-top: 10px;">
                                        <form class="layui-form layui-form-pane" action="" style="display: block;margin-top: 25px;">
                                            <div class="layui-form-item">
                                                <label class="layui-form-label">标题:</label>
                                                <div class="layui-input-block">
                                                    <input type="text" id="name` + uuid + `" name="name" value="" placeholder="请输入标题" autocomplete="off" class="layui-input">
                                                </div>
                                            </div>
                                            <div class="layui-form-item">
                                                <label class="layui-form-label">内容:</label>
                                                <div class="layui-input-block">
                                                     <textarea id="synopsis` + uuid + `" name="synopsis" placeholder="请输入内容" class="layui-textarea"></textarea>
                                                </div>
                                            </div>
                                            <div class="layui-form-item">
                                                <label class="layui-form-label">排序:</label>
                                                <div class="layui-input-block">
                                                     <input type="number" id="sort` + uuid + `" name="sort" value="" placeholder="请输入排序" autocomplete="off" class="layui-input">
                                                </div>
                                            </div>
                                        </form>
                                        <div>
                                            <a class="layui-btn layui-btn-sm" uurid="` + uuid + `" id="grszGSLGridAddId_btn" style="position: absolute;bottom: 10px;right: 12px;">确定修改</a>
                                        </div>
                                    </div>
                                    `,
                                    success: function () {
                                        $("#grszGSLGridAddId_btn").click(function () {
                                            var uurid = $(this).attr("uurid");
                                            var name = $("#name" + uurid).val();
                                            if (name == undefined || name == null || name == "") {
                                                kaMsg.error({ "code": "500", "msg": "标题不能为空！" });
                                                return false;
                                            }
                                            var synopsis = $("#synopsis" + uurid).val();
                                            if (synopsis == undefined || synopsis == null || synopsis == "") {
                                                kaMsg.error({ "code": "500", "msg": "内容不能为空！" });
                                                return false;
                                            }
                                            var newtype = $("#newtype" + uurid).val();
                                            if (newtype == undefined || newtype == null || newtype == "") {
                                                kaMsg.error({ "code": "500", "msg": "类型不能为空！" });
                                                return false;
                                            }
                                            var sort = $("#sort" + uurid).val();
                                            if (sort == undefined || sort == null || sort == "") {
                                                kaMsg.error({ "code": "500", "msg": "排序不能为空！" });
                                                return false;
                                            }
                                            var option = kaValue.getUrl("ncpcAdd");
                                            option.async = false;
                                            option.data = {
                                                "name": name,
                                                "synopsis": synopsis,
                                                "newtype": newtype,
                                                "sort": sort
                                            }
                                            option.success = function (re) {
                                                if (re.code == 200) {
                                                    layer.close(index);
                                                    kagrid.getData(config, function (reData, config) {
                                                        var gridApi = kagrid.getGridApi(config.id);
                                                        gridApi.setRowData(reData);
                                                        kagrid.playUpSort(config);
                                                    })
                                                } else {
                                                    kaMsg.error({ "code": re.code, "msg": re.msg });
                                                }
                                            }
                                            ka.ajax(option);
                                        })
                                    }
                                });
                            }
                        },
                        {
                            id: "grszGSLGridDeleteIdS",
                            title: "删除",
                            ico: `icon-times-circle`,
                            cb: function (config) {
                                var gridApi = ka_grid_api.get(config.id).gridApi;
                                var selectedRowsData = gridApi.getSelectedRows();
                                if (selectedRowsData.length <= 0) {
                                    kaMsg.error({ "code": 1000, "msg": "请选择至少一条数据！" });
                                    return false;
                                }
                                var dst = [];
                                for (var i in selectedRowsData) {
                                    dst.push(selectedRowsData[i].id);
                                }
                                var dataStr = dst.join(",");
                                kaMsg.warn({ "code": 110, "msg": "确定删除吗？",cb:function(){
                                    var option = kaValue.getUrl("ncpcRemove");
                                    option.url = option.url + "/" + dataStr;
                                    option.success = function (re) {
                                        if (re.code == 200) {
                                            kagrid.getData(config, function (reData, config) {
                                                var gridApi = kagrid.getGridApi(config.id);
                                                gridApi.setRowData(reData);
                                                kagrid.playUpSort(config);
                                            })
                                        } else {
                                            kaMsg.error({ "code": re.code, "msg": re.msg });
                                        }
                                    }
                                    ka.ajax(option);
                                } });
                            }
                        }
                    ],
                },
                button: {
                    type: 4, //【1:URL,2:本地JSON,3:外站URL,4:自定义JSON】
                    datajson: [
                        {
                            id: "grszGSLGridEditId",
                            title: "编辑",
                            cb: function (d) {
                                var config = d.colDef.kaconfig;
                                var uuid = ka.uuidStr();
                                layui.layer.open({
                                    type: 1, // page 层类型
                                    area: ['537px', '360px'],
                                    title: `
                                    <i class="icon iconfont icon-mail" style="margin-top: 10px;text-align: center;width: 50px;height: 50px;line-height: 50px;font-size: 30px;float: left;position: absolute;background-color: #f3f1ff;border-radius: 50%;"></i>
                                    <div style="font-size: 18px;font-weight: bold;margin-left: 70px;margin-top: 5px;position: absolute;">编辑公示栏</div>
                                    <div style="color: #989898;margin-top: 35px;margin-left: 70px;font-size: 12px;position: absolute;">用于自己推广</div>
                                    `,
                                    offset: ['20%', '30%'],
                                    shade: [0.6, '#FFF'], // 点击遮罩区域，关闭弹层
                                    maxmin: false, // 允许全屏最小化
                                    anim: 0, // 0-6 的动画形式，-1 不开启
                                    content: `
                                    <input type="hidden" id="newtype` + uuid + `" name="newtype" value="1" placeholder="类型" autocomplete="off" class="layui-input">
                                    <input type="hidden" id="id` + uuid + `" name="id" value="` + d.data.id + `" placeholder="id" autocomplete="off" class="layui-input">
                                    <div style="padding-left: 15px;padding-right: 15px;padding-top: 10px;">
                                        <form class="layui-form layui-form-pane" action="" style="display: block;margin-top: 25px;">
                                            <div class="layui-form-item">
                                                <label class="layui-form-label">标题:</label>
                                                <div class="layui-input-block">
                                                    <input type="text" id="name` + uuid + `" name="name" value="` + d.data.name + `" placeholder="请输入标题" autocomplete="off" class="layui-input">
                                                </div>
                                            </div>
                                            <div class="layui-form-item">
                                                <label class="layui-form-label">内容:</label>
                                                <div class="layui-input-block">
                                                     <textarea id="synopsis` + uuid + `" name="synopsis" placeholder="请输入内容" class="layui-textarea">` + d.data.synopsis + `</textarea>
                                                </div>
                                            </div>
                                            <div class="layui-form-item">
                                                <label class="layui-form-label">排序:</label>
                                                <div class="layui-input-block">
                                                     <input type="number" id="sort` + uuid + `" name="sort" value="` + d.data.sort + `" placeholder="请输入排序" autocomplete="off" class="layui-input">
                                                </div>
                                            </div>
                                        </form>
                                        <div>
                                            <a class="layui-btn layui-btn-sm" uurid="` + uuid + `" id="grszGSLGridEditId_btn" style="position: absolute;bottom: 10px;right: 12px;">确定修改</a>
                                        </div>
                                    </div>
                                    `,
                                    success: function () {
                                        $("#grszGSLGridEditId_btn").click(function () {
                                            var uurid = $(this).attr("uurid");
                                            var name = $("#name" + uurid).val();
                                            if (name == undefined || name == null || name == "") {
                                                kaMsg.error({ "code": "500", "msg": "标题不能为空！" });
                                                return false;
                                            }
                                            var synopsis = $("#synopsis" + uurid).val();
                                            if (synopsis == undefined || synopsis == null || synopsis == "") {
                                                kaMsg.error({ "code": "500", "msg": "内容不能为空！" });
                                                return false;
                                            }
                                            var newtype = $("#newtype" + uurid).val();
                                            if (newtype == undefined || newtype == null || newtype == "") {
                                                kaMsg.error({ "code": "500", "msg": "类型不能为空！" });
                                                return false;
                                            }
                                            var sort = $("#sort" + uurid).val();
                                            if (sort == undefined || sort == null || sort == "") {
                                                kaMsg.error({ "code": "500", "msg": "排序不能为空！" });
                                                return false;
                                            }
                                            var id = $("#id" + uurid).val();
                                            if (id == undefined || id == null || id == "") {
                                                kaMsg.error({ "code": "500", "msg": "ID不能为空！" });
                                                return false;
                                            }
                                            var option = kaValue.getUrl("ncpcEdit");
                                            option.data = {
                                                "id": id,
                                                "name": name,
                                                "synopsis": synopsis,
                                                "sort": sort,
                                                "newtype": newtype,
                                                "uuid": uuid
                                            }
                                            option.success = function (re) {
                                                if (re.code == 200) {
                                                    kagrid.getData(config, function (reData, config) {
                                                        var gridApi = kagrid.getGridApi(config.id);
                                                        gridApi.setRowData(reData);
                                                        kagrid.playUpSort(config);
                                                    })
                                                } else {
                                                    kaMsg.error({ "code": re.code, "msg": re.msg });
                                                }
                                            }
                                            ka.ajax(option);
                                        })
                                    }
                                });
                            }
                        },
                        {
                            id: "grszGSLGridDeleteId",
                            title: "删除",
                            cb: function (d) {
                                var dataStr = d.data.id;
                                var config = d.colDef.kaconfig;
                                kaMsg.warn({ "code": 110, "msg": "确定删除吗？",cb:function(){
                                    var option = kaValue.getUrl("ncpcRemove");
                                    option.url = option.url + "/" + dataStr;
                                    option.success = function (re) {
                                        if (re.code == 200) {
                                            kagrid.getData(config, function (reData, config) {
                                                var gridApi = kagrid.getGridApi(config.id);
                                                gridApi.setRowData(reData);
                                                kagrid.playUpSort(config);
                                            })
                                        } else {
                                            kaMsg.error({ "code": re.code, "msg": re.msg });
                                        }
                                    }
                                    ka.ajax(option);
                                } });
                            }
                        }
                    ]
                },
                column: []
            };
            var gerenszIndexDiv25Html = kagrid.getHtml(giBody);
            $("#gerenszIndexDiv25_content").html(`<div style="height: 654px;">` + gerenszIndexDiv25Html + `</div>`);
            kagrid.loading(giBody);
        });
    },
    getUserInfor: function () {
        var userInfor = {};
        var option = kaValue.getUrl("getInfo");
        option.async = false;
        option.success = function (re) {
            if (re.code == 200) {
                userInfor = re;
            }
        }
        ka.ajax(option);
        return userInfor;
    },
    updateNickName: function (nickNameNew, userId) {
        var option = kaValue.getUrl("UpdateNickName");
        var nickName = $("#nickNameId").val();
        if (nickNameNew == undefined || nickNameNew == null || nickNameNew == "") {
            kaMsg.error({ "msg": "昵称不能为空！", "code": "500" });
        } else {
            if (nickNameNew == nickName) {
                kaMsg.error({ "msg": "昵称没有修改！", "code": "500" });
            } else {
                option.data = {
                    "nickName": nickName
                }
                option.async = false;
                option.success = function (re) {
                    if (re.code == 200) {
                        kaMsg.success(re);
                        window.location.reload();
                    } else {
                        kaMsg.error(re);
                    }
                }
                ka.ajax(option);
            }
        }
    },
    updatePwd: function (nickNameNew, userId) {
        var option = kaValue.getUrl("updatePwd");
        var oldPassword = $("#oldPasswordId").val();
        var newPassword = $("#newPasswordId").val();
        var newPasswordCF = $("#newPasswordCFId").val();
        if (oldPassword == undefined || oldPassword == null || oldPassword == "") {
            kaMsg.error({ "msg": "原密码不能为空！", "code": "500" });
        } else if (newPassword == undefined || newPassword == null || newPassword == "") {
            kaMsg.error({ "msg": "新密码不能为空！", "code": "500" });
        } else if (newPasswordCF == undefined || newPasswordCF == null || newPasswordCF == "") {
            kaMsg.error({ "msg": "重复新密码不能为空！", "code": "500" });
        } else {
            option.data = {
                "oldPassword": oldPassword,
                "newPassword": newPassword,
                "newPasswordCF": newPasswordCF
            }
            option.async = false;
            option.success = function (re) {
                if (re.code == 200) {
                    kaMsg.success(re);
                    window.location.reload();
                } else {
                    kaMsg.error(re);
                }
            }
            ka.ajax(option);
        }
    }
}